package com.songlanyun.modules.rabbitmq.mq.consumer;


import com.alibaba.fastjson.JSONObject;
import com.rabbitmq.client.Channel;
import com.songlanyun.modules.notifytemp.model.dto.WxNotifyDTO;
import com.songlanyun.modules.notifytemp.service.NotifyTempService;
import com.songlanyun.modules.rabbitmq.MqConstant;
import com.songlanyun.modules.rabbitmq.service.MessageHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.io.IOException;

/**
 * 小程序消息消费者
 */
@Component
@Slf4j
public class WxNotifyConsumer extends BaseConsumer {

    @Resource
    private NotifyTempService notifyTempService;

    @Override
    protected void process(Message message) {
        JSONObject msgBody = MessageHelper.msgToObj(message, JSONObject.class);
        WxNotifyDTO dto = JSONObject.toJavaObject(msgBody, WxNotifyDTO.class);

        //发送消息
        notifyTempService.sendWxNotify(dto);

    }

    @RabbitListener(queues = MqConstant.WxNotifyConstant.WX_NOTIFY_QUEUE)
    public void consume(Message message, Channel channel) throws IOException {
        super.handle(message, channel);
    }
}
